package com.example.campsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.campsystem.entity.Bookings;
import com.example.campsystem.entity.Camps;
import com.example.campsystem.service.BookingsService;
import com.example.campsystem.mapper.BookingsMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author GJC
* @description 针对表【bookings(预订表)】的数据库操作Service实现
* @createDate 2025-04-20 23:23:47
*/
@Service
public class BookingsServiceImpl extends ServiceImpl<BookingsMapper, Bookings>
    implements BookingsService{
    @Override
    public boolean createBooking(Bookings bookings) {
        return this.baseMapper.insert(bookings) > 0;
    }

    @Override
    public boolean updateBookingStatus(Bookings bookings) {
        QueryWrapper<Bookings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", bookings.getUserId());
        queryWrapper.eq("camp_id", bookings.getCampId());
        return this.baseMapper.update(bookings, queryWrapper) > 0;
    }

    @Override
    public boolean deleteBooking(Bookings bookings) {
        QueryWrapper<Bookings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", bookings.getUserId());
        queryWrapper.eq("camp_id", bookings.getCampId());
        return this.baseMapper.delete(queryWrapper) > 0;
    }
}




